function f_get_alter_sql()
{   #格式化sql语句, 统一使用一个空格分隔
    #检查alter操作是否支持, 目前只支持add modify两个动作, 检查完毕后合并sql, 将同一个表的alter合并到一条alter语句, 并保存到alter_file_tmp2文件
    declare opt_count drop_pri_mark add_pri_mark fun_name
    fun_name="f_get_alter_sql"
    echo "${new_line}"|tr ";" "\n" |sed 's/^[ \t]*//g;s/$/;/g'|sed "/^;$/d"|awk '{for(i=1;i<=NF;i++)printf $i " ";printf"\n"}' > ${alter_file_tmp1}  
    if [ "$(grep -vicP "^[ \t]*alter table " ${alter_file_tmp1})x" != "0x" ]
    then
        grep -viP "^[ \t]*alter table " ${alter_file_tmp1} || true
        f_logging "ERROR:${fun_name}" "您的需求是改表, 但是提交的sql语句中, 存在其他类型sql(如上显示), 请检查后重新提交" "2" "1"
    elif [ "$(grep -icP "^[ \t]*alter table " ${alter_file_tmp1})x" == "0x" ]
    then
        f_logging "ERROR:${fun_name}" "您的需求是改表, 但是提交的sql语句中, 没有改表语句, 请检查后重新提交" "2" "1"
    fi
    for ((i=1; i<=$(wc -l < ${alter_file_tmp1}); i++))
    do
        line="$(sed -n "${i}p" ${alter_file_tmp1})"
        table_name="$(awk '{print $3}' <<< "${line}"|awk -F '(' '{print $1}')"
        mysql_table_name="${table_name}"
        echo "${line}"|tr "," "\n"|sed -r "s/^\<alter table\>//i;s/\<table\>//i"|sed "s/^ \<${table_name}\> //1"|sed 's/^[ \t]*//g' > ${alter_file_tmp2}
        f_check_mysql_for_key_word "${table_name}" "表名" "table" "${line}"
        _a="(^add *(|index|key|column|unique))"                                        #add操作
        _m="(^modify *(|column))"                                                      #modify操作
        _r="(^rename (key|index|column|to|))"                                          #rename操作
        _d="(^drop *(|index|key|column))"                                              #drop操作
        _o="(^(engine|comment|change|ROW_FORMAT[ ]*=[ ]*(compact|redundant|dynamic|compressed)( *KEY_BLOCK_SIZE[ ]*=[ ]*[0-9]*|)))" #修改引擎,修改注释,change操作,行格式
        _character="armscii8|ascii|big5|binary|cp1250|cp1251|cp1256|cp1257|cp850|cp852|cp866|cp932|dec8|eucjpms|euckr|gb2312|gbk|geostd8"    #支持的字符集
        _character="${_character}|greek|hebrew|hp8|keybcs2|koi8r|koi8u|latin1|latin2|latin5|latin7|macce|macroman|sjis|swe7|tis620|ucs2"     #支持的字符集
        _character="${_character}|ujis|utf16|utf16le|utf32|utf8|utf8mb4"                                                                     #支持的字符集
        _c="(^(((default |)character set *=?)|(CONVERT TO character set)))"                          #修改字符集
        _cc="(^(((default |)character set *=?)|(CONVERT TO character set)) *(${_character}))"        #是否支持该字符集
        _i="(^(comment .*|auto_increment) *= *)"                                                     #修改自增, 值错误
        _ii="(^(comment .*|auto_increment) *= *[1-9][0-9]*)"                                         #修改自增
        _no_oth="(^(alter|truncate|partition)|(^(add|drop|DISCARD|IMPORT|COALESCE|ANALYZE|CHECK) partition))" #不支持这些操作
        _no_key="((^add (CONSTRAINT|FOREIGN KEY|PRIMARY KEY))|(^drop (PRIMARY |FOREIGN )KEY))"                #不支持对索引的这些操作
        drop_pri_mark=0                                                                #删除主键的标志
        add_pri_mark=0                                                                 #添加主键的标志
        opt_count="$(wc -l < ${alter_file_tmp2})"                                      #该行alter操作总共有几个改表动作

        if [ "${sup_add_unique_key}x" == "1x" ]
        then #允许加唯一索引
            _a_uk="|(^add unique)"                                        #add操作
        else #不允许加唯一索引
            _no_uk="|(^add unique)"                                       #不支持这些操作
        fi

        for ((j=1;j<=${opt_count};j++))
        do
            row="$(sed -n "${j}p" ${alter_file_tmp2})"
            row_tmp="$(sed "s/${var_str2}/,/g" <<< "${row}")"
            {
                _is_ok="$(grep -Pwic "(${_a}|${_m}|${_r}|${_o}|${_d}|${_c}|${_i}${_a_uk})" <<< "${row}")"
                _is_not_ok="$(grep -Pwic "(${_no_oth}|${_no_key}${_no_uk})" <<< "${row}")"
                _is_add="$(grep -wic "^add" <<< "${row}")"
                _is_add_column="$(grep -wic "^add column" <<< "${row}")"
                _is_drop="$(grep -wic "^drop" <<< "${row}")"
                _is_drop_column="$(grep -wic "^drop column" <<< "${row}")"
                _is_rename_column="$(grep -wic "^rename column" <<< "${row}")"
                _is_rename_table="$(grep -wi "^rename" <<< "${row}"|grep -vEc "^((rename column)|(rename (index|key)))")"
                _is_rename_as="$(grep -wic "^rename as" <<< "${row}")"
                _is_rename_one="$(grep -ciP "^rename [\w]{1,}[ ;]*$" <<< "${row}")"
                _is_rename_index="$(grep -Pwic "^rename (index|key)" <<< "${row}")"
                _is_change="$(grep -wic "^change" <<< "${row}")"
                _is_change_column="$(grep -wic "^change column" <<< "${row}")"
                _is_add_index="$(grep -iP "^add (index|key|unique)" <<< "${row}"|grep -c "(")"
                _is_add_uindex="$(grep -iP "^add unique " <<< "${row}"|grep -c "(")"
                _is_add_full_index="$(grep -iP "^add fulltext (index|key)" <<< "${row}"|grep -c "(")"
                _is_drop_index="$(grep -wicP "^drop (index|key)" <<< "${row}")"
                _is_drop_pri="$(grep -wicP "^drop primary key" <<< "${row}")"
                _is_add_pri="$(grep -wicP "^add primary key" <<< "${row}")"
                _is_modify="$(grep -wic "^modify" <<< "${row}")"
                _is_modify_column="$(grep -wic "^modify column" <<< "${row}")"
                _is_comment="$(grep -wic "comment" <<< "${row}")"
                _is_auto_increment="$(grep -Pwic "(${_i})" <<< "${row}")"            #修改auto increment的操作
                _is_error_auto_increment="$(grep -Pwic "(${_ii})" <<< "${row}")"     #但是指定的值是错误的

                _is_set_character="$(grep -Pwic "(${_c})" <<< "${row}")"             #修改auto increment的操作
                _is_error_character="$(grep -Pwic "(${_cc})" <<< "${row}")"          #但是指定的值是错误的

                declare __3 __4
                __3="$(awk '{print $3}' <<< "${row}"|awk -F'(' '{print $1}'|awk -F';' '{print $1}')"
                __4="$(awk '{print $4}' <<< "${row}"|awk -F'(' '{print $1}'|awk -F';' '{print $1}')"
                [ -z "${__3}" ] && {
                    [ "${_is_drop_column}x" != "0x" ] && _is_drop_column="0"                     #第三个单词为空, 如果是drop column表示说column是字段名
                    [ "${_is_drop_index}x" != "0x" ] && _is_drop_index="0"                       #第三个单词为空, 如果是drop index表示说index是字段名
                    [ "${_is_rename_index}x" != "0x" ] && _is_rename_index="0"                   #第三个单词为空, 如果是rename index表示说index是表名
                    [ "${_is_rename_column}x" != "0x" ] && _is_rename_column="0"                 #第三个单词为空, 如果是rename column表示说column是表名
                    [ "${_is_rename_as}x" != "0x" ] && _is_rename_as="0"                         #第三个单词为空, 如果是rename as表示说as是表名
                    [ "$(grep -wic "^rename" <<< "${row}")x" != "0x" ] && _is_rename_table="1"   #第三个单词为空, 如果是rename table恒=1
                }
                __3="$(f_check_data_type "${__3}")"    #如果第三个单词是数据类型, 则表示add|modify column的column不是作为操作关键字使用, 而是作为列名
                __4="$(f_check_data_type "${__4}")"    #如果第四个单词是数据类型, 则表示change column的column不是作为操作关键字使用, 而是作为列名
                [ "${__3}x" != "0x" -a "${__4}x" == "0x" ] && _is_add_column="0"
                [ "${__3}x" != "0x" -a "${__4}x" == "0x" ] && _is_modify_column="0"
                [ "${__4}x" != "0x" ] && _is_change_column="0"
                unset __3 __4
            } || true


            if [ "${_is_add}x" != "0x" -o "${_is_modify}x" != "0x" ] && [ "${_is_comment}x" == "0x" ]
            then #添加和modify操作建议带上comment属性
                [ "${check_mode_opt}x" == "strictx" ] && f_logging "REMAIND:${fun_name}" "'${table_name}' 表的 { ${row_tmp} } 操作, 请使用 'comment' 属性添加注释" >&2
                all_sql_is_ok=0
            fi

            if [ "${_is_add_pri}x" == "1x" ]
            then
                add_pri_mark=1
                if [ "${drop_pri_mark}x" != "1x" ] 
                then #不支持直接添加主键, 如果有这种add primary key的动作, 必须要求前面有drop primary key
                    f_logging "ERROR:${fun_name}" "目前还不支持像 '${table_name}' 表的 { ${row_tmp}} 这种操作 ]" >&2
                    one_sql_is_error=0 && all_sql_is_ok=0 && continue
                elif [ "${force_tool}x" != "0x" ] #表示有改主键的操作, 统一使用gh-ost去操作
                then
                    f_logging "WARN:${fun_name}" "'${table_name}' 表的 alter 语句有更新主键操作, 本次将强制使用gh-ost进行改表操作 ]" "2" >&2
                    format_mark="1" && idc_mark="1"
                fi
            fi

            if [ "${mysql_version:0:1}x" != "8x" ]
            then
                __="${mysql_version}版本, 不支持 '${table_name}' 表的 {${row_tmp}} 操作. 8.0 才支持"
                if [ "${_is_rename_column}x" != "0x" ]
                then # rename column, 判断版本号, 8.0才支持
                     __="${__}'RENAME COLUMN old_col_name TO new_col_name'"
                    one_sql_is_error=0 && all_sql_is_ok=0
                elif [ "${_is_rename_index}x" != "0x" ]
                then # rename index, 判断版本号, 8.0才支持
                     __="${__}'RENAME {INDEX|KEY} old_index_name TO new_index_name'"
                    one_sql_is_error=0 && all_sql_is_ok=0
                elif [ "${_is_rename_as}x" != "0x" ]
                then # rename as, 判断版本号, 8.0才支持
                     __="${__}'RENAME AS new_table_name', 该版本请使用rename to new_table_name"
                    one_sql_is_error=0 && all_sql_is_ok=0
                fi
                [ "${one_sql_is_error}x" == "0x" -a "${all_sql_is_ok}x" == "0x" ] && { f_logging "ERROR:${fun_name}" "${__}" >&2 && continue ;} || __=""
            fi

            if [ "${_is_auto_increment}x" == "1x" ] && [ "${_is_error_auto_increment}x" == "0x" ]
            then
                f_logging "ERROR:${fun_name}" "使用了auto_increment操作, 但是指定的值[${row}]不正确, 请检查" >&2
                one_sql_is_error=0 && all_sql_is_ok=0 && continue
            elif [ "${_is_set_character}x" == "1x" ] && [ "${_is_error_character}x" == "0x" ]
            then
                f_logging "ERROR:${fun_name}" "使用了修改表字符集操作, 但是指定的字符集[${row}]不支持, 请检查" >&2
                one_sql_is_error=0 && all_sql_is_ok=0 && continue
            fi

            if [ "${_is_drop_pri}x" == "1x" ]
            then #如果有drop primary key的操作就标记一下
                drop_pri_mark=1
            fi

            if [ "${j}x" == "${opt_count}x" ] && [ "${drop_pri_mark}x" == "1x" ] && [ "${add_pri_mark}x" != "1x" ]
            then #如果遍历到最后一个动作了, 但是检查到有drop primary key, 而没有检查到add primary则认为这是错误的操作
                f_logging "ERROR:${fun_name}" "'${table_name}' 表的alter操作中有drop primari key的动作, 但是没检查到有add primary key的动作, 暂不支持这种操作 ]" "2" >&2
                one_sql_is_error=0 && all_sql_is_ok=0 && continue
            fi

            if [ "${_is_ok}x" == "0x" ] || [ "${_is_not_ok}x" == "1x" ]
            then #不支持不在_is_ok中的操作, 不支持在_is_not_ok中的操作
                if [ "${drop_pri_mark}x" != "1x" ] && [ "${add_pri_mark}x" != "1x" ]    #如果有add primary key的动作就视为支持的操作, 如果没有就视为不支持的操作
                then #如果是drop primary key先不设置one_sql_is_error=0, 等所有动作都遍历完, 需要判断是否有add primary key
                    __="目前还不支持像 '${table_name}' 表的 { ${row_tmp}} 这种操作"
                    f_logging "ERROR:${fun_name}" "${__} ]" >&2
                    if [ "${_is_add_uindex}x" == "1x" ]
                    then
                        f_logging "ERROR:${fun_name}" "添加唯一索引有丢数据的风险(目标索引列存在重复值的话就会丢数据), 请与业务协商是否能接受丢数据的风险" >&2
                        f_logging "ERROR:${fun_name}" "如果能接受丢数据的风险或者能保证这个唯一键的列没有重复值" >&2
                        f_logging "ERROR:${fun_name}" "可以修改 ${dbadb_db} 下的表 ${t_state_task} 将unique_key 列置为1. 详细操作可以参见api文档" >&2
                    fi

                    one_sql_is_error=0 && all_sql_is_ok=0 && continue
                fi
            elif [ "${_is_add_column}x" != "0x" -o "${_is_modify_column}x" != "0x" -o "${_is_drop_column}x" != "0x" -o "${_is_drop_index}x" != "0x" ]
            then # add column , modify column, drop column | index
                if [ "${_is_add_column}x" != "0x" ]
                then #如果是加字段就预防column属性和左括号连一起,导致获取表名异常, 所以用sed处理一下
                    col_name="$(sed 's/\<column\>(/column (/gi' <<< "${row}"|awk '{print $3}')"
                else
                    col_name="$(awk '{print $3}' <<< "${row}")"
                fi

                if [ "$(grep -c "^(" <<< "${col_name}")x" == "1x" ] && [ "${_is_add_column}x" != "0x" ] 
                then #如果是add column且以左括号开始, 表示add column (c1 int, c2 int, c3 int)这种语法, 这种语法需要特殊处理, 需要获取字段列表及数据类型
                    column_list="$(f_delete_for_string <<< "$(sed "s/${var_str2}/,/g" <<< "${row}")" "nosed"|sed 's/comment//gi')"
                    column_list=($(tr "," "\n" <<< "${column_list}"|sed 's/\<add column\> *(/\n/g'|sed '/^$/d;s/(.*//g'|awk '{print $1":::"$2}'))
                    for col_name in ${column_list[@]}
                    do
                        _col_name_type="$(awk -F':::' '{print $2}' <<< "${col_name}"|awk -F '(' '{print $1}')"  #获取数据类型所在的位置的字符串
                        col_name_type="$(f_check_data_type "${_col_name_type}")"                                #判断是否是mysql支持的数据类型
                        col_name="$(awk -F':::' '{print $1}' <<< "${col_name}")"                                #字段名
                        if [ "$(grep -wiPc "(key|index)" <<< "${col_name}")x" == "1x" ] && [ "${col_name_type}x" == "1x" ]
                        then #使用了index|key, 且_col_name_type是mysql合法数据类型, 就表明是使用了index|key这个关键字作为列名
                            f_check_mysql_for_key_word "${col_name}" "列名, '${row_tmp}'" "col" "${line}" "${row}"
                        elif [ "$(grep -wiPc "(key|index)" <<< "${col_name}")x" == "1x" ]
                        then #表示使用了index或者key这种关键字, 这种情况需要判断index|key后面的字符串是不是数据类型, 如果是就是说使用了index|key作为列名
                            if [ -z "${_col_name_type}" ]                                                            #反之就是加索引操作
                            then #加索引操作
                                index_name="null_index_name"
                                f_return_check_result "${index_name}" "检测到添加索引的时候没有指定索引名, 请为该索引指定一个索引名称 '${row_tmp}'" >&2
                                f_logging "REMAIND:${fun_name}" "建议 : 普通索引使用 'ik_xxx' , 唯一索引使用 'uk_xxx' 这种命名习惯" >&2
                            fi
                            f_check_mysql_for_key_word "${_col_name_type}" "索引名, '${row_tmp}'" "index" "${line}" "${row}"
                        fi
                        mysql_table+=(["${mysql_table_name}"]=" ${col_name}")
                    done
                else #其他操作, 检查列是否使用保留字
                    f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                    mysql_table+=(["${mysql_table_name}"]=" ${col_name}")
                fi
            elif [ "${_is_rename_column}x" != "0x" ]
            then #rename column
                col_name="$(awk '{print $3}' <<< "${row}")"
                f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                col_name="$(awk '{print $5}' <<< "${row}")"
                f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
            elif [ "${_is_rename_index}x" != "0x" ]
            then # rename index
                column_list=($(awk '{print $3" "$5}' <<< "${row}"))
                for col_name in ${column_list[@]}
                do
                    f_check_mysql_for_key_word "${col_name}" "索引列名, { ${row_tmp} }" "col" "${line}" "${row}"
                done
            elif [ "${_is_rename_table}x" != "0x" ]
            then # rename table
                if [ "$(grep -wic "^rename to" <<< "${row}")x" == "1x" ] 
                then
                    f_check_mysql_for_key_word "$(awk '{print $3}' <<< "${row}"|awk -F';' '{print $1}')" "表名" "table" "${line}"
                elif [ "$(grep -wic "^rename as" <<< "${row}")x" == "1x" ]
                then ##rename as new_table --> rename to new_table
                    __="$(awk '{print $3}' <<< "${row}"|awk -F';' '{print $1}')"
                    line="$(sed "s/\<rename as ${__}\>/rename to ${__}/gi" <<< "${line}")"
                    row="$(sed "s/^\<rename as\>/rename to/gi" <<< "${row}")"
                    f_check_mysql_for_key_word "$(awk '{print $3}' <<< "${row}")" "表名" "table" "${line}"
                elif [ "${_is_rename_one}x" == "1x" ]  #rename new_table --> rename to new_table, 就是说rename后面只能是一个单词
                then
                    __="$(awk '{print $2}' <<< "${row}"|awk -F';' '{print $1}')"
                    line="$(sed "s/\<rename ${__}\>/rename to ${__}/gi" <<< "${line}")"
                    row="$(sed "s/^\<rename\>/rename to/gi" <<< "${row}")"
                    f_check_mysql_for_key_word "$(awk '{print $3}' <<< "${row}")" "表名" "table" "${line}"
                else
                    f_logging "ERROR:${fun_name}" "'${row}' in '${line}' 不识别这个语法, 请检查！！！" >&2
                    one_sql_is_error=0 && all_sql_is_ok=0
                fi
            elif [ "${_is_add_index}x" != "0x" ] || [ "${_is_add_full_index}x" != "0x" ]
            then #add index / add full index
                F_str="$(awk '{if(NR==1){for(i=1;i<=2;i++)printf $i " ";printf"\n"}}' <<< "${row}"|awk -F '(' '{print $1}')"
                if [ "${_is_add_full_index}x" != "0x" ]
                then
                    F_str="$(awk '{if(NR==1){for(i=1;i<=3;i++)printf $i " ";printf"\n"}}' <<< "${row}"|awk -F '(' '{print $1}')"
                fi
                index_name="$(awk -F "(" '{print $1}' <<< "${row}"|awk -F "${F_str}" '{print $2}')"
                if [ -z "${index_name}" ] 
                then
                    index_name="null_index_name"
                    f_return_check_result "${index_name}" "检测到添加索引的时候没有指定索引名, 请为该索引指定一个索引名称 '${row_tmp}'" >&2
                    f_logging "REMAIND:${fun_name}" "建议 : 普通索引使用 'ik_xxx' , 唯一索引使用 'uk_xxx' 这种命名习惯" >&2
                fi
                f_check_mysql_for_key_word "${index_name}" "索引名, { ${row_tmp} }" "index" "${line}" "${row}"
                F_str="$(awk -F '(' '{print $1}' <<< "${row}")"
                column_list="$(awk -F "${F_str}" '{print $NF}' <<< "${row}"|sed -r 's#\(\s{0,}[0-9][^)]+\)##g')"
                column_list=($(awk 'BEGIN{ FS="(" ; RS=")" } NF>1 { print $NF }' <<< "${column_list}"|sed "s/${var_str2}/\n/g"|awk '{print $1}')) 
                #只要第一个单词, 避免用户使用正序或者倒叙这种关键字
                for col_name in ${column_list[@]}
                do
                    f_check_mysql_for_key_word "${col_name}" "索引列名, { ${row_tmp} }" "col" "${line}" "${row}"
                done
            elif [ "${_is_change_column}x" != "0x" ]
            then #_is_change_column
                col_name="$(awk '{print $3}' <<< "${row}")"
                f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                col_name="$(awk '{print $4}' <<< "${row}")"
                f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                mysql_table+=(["${mysql_table_name}"]=" ${col_name}")
            elif [ "${_is_change}x" != "0x" ]
            then #_is_change
                col_name="$(awk '{print $2}' <<< "${row}")"
                f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                col_name="$(awk '{print $3}' <<< "${row}")"
                f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                mysql_table+=(["${mysql_table_name}"]=" ${col_name}")
            elif [ "${_is_add}x" != "0x" ] || [ "${_is_modify}x" != "0x" ] || [ "${_is_drop}x" != "0x" ]
            then #add 操作, modify操作 drop操作
                if [ "${_is_add}x" != "0x" ]
                then
                    col_name="$(sed 's/\<add\>(/add (/gi' <<< "${row}"|awk '{print $2}')"
                else
                    col_name="$(awk '{print $2}' <<< "${row}")"
                fi

                if [ "$(grep -c "^(" <<< "${col_name}")x" == "1x" ] && [ "${_is_add}x" != "0x" ]
                then #针对 add (c1 int, c2 int, c3 int)这种语法
                    column_list="$(f_delete_for_string <<< "$(sed "s/${var_str2}/,/g" <<< "${row}")" "nosed"|sed 's/comment//gi')"
                    column_list=($(tr "," "\n" <<< "${column_list}"|sed 's/\<add column\> *(/\n/g'|sed '/^$/d;s/(.*//g'|awk '{print $1":::"$2}'))
                    for col_name in ${column_list[@]}
                    do
                        _col_name_type="$(awk -F':::' '{print $2}' <<< "${col_name}"|awk -F '(' '{print $1}')"
                        col_name_type="$(f_check_data_type "${_col_name_type}")"
                        col_name="$(awk -F':::' '{print $1}' <<< "${col_name}")"
                        if [ "$(grep -wiPc "(key|index)" <<< "${col_name}")x" == "1x" ] && [ "${col_name_type}x" == "1x" ]
                        then
                            f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                        elif [ "$(grep -wiPc "(key|index)" <<< "${col_name}")x" == "1x" ]
                        then
                            if [ -z "${_col_name_type}" ] 
                            then
                                index_name="null_index_name"
                                f_return_check_result "${index_name}" "检测到添加索引的时候没有指定索引名, 请为该索引指定一个索引名称 '${row_tmp}'" >&2
                                f_logging "REMAIND:${fun_name}" "建议 : 普通索引使用 'ik_xxx' , 唯一索引使用 'uk_xxx' 这种命名习惯" >&2
                            fi
                            f_check_mysql_for_key_word "${_col_name_type}" "索引名, { ${row_tmp} }" "index" "${line}" "${row}"
                        fi
                        mysql_table+=(["${mysql_table_name}"]=" ${col_name}")
                    done
                else
                    f_check_mysql_for_key_word "${col_name}" "列名, { ${row_tmp} }" "col" "${line}" "${row}"
                    mysql_table+=(["${mysql_table_name}"]=" ${col_name}")
                fi
                if [ "${_is_modify}x" != "0x" ]
                then #如果是modify操作就将modify改成modify column 方便后面判断modify是否符合onlineddl
                    __row="$(sed 's/^\<modify\>/modify column/gi' <<< "${row}")" || true
                    line="$(sed "s/${row}/${__row}/g" <<< "${line}")" || true
                fi
            fi

            #判断是否使用了after|first关键字, 第一个grep表示以after xxx;这种结尾的, 避免after关键字被用作字段名, 如alter table t add after int after name
            _after_first="$(f_delete_for_string <<< "${row}"|grep -iPo " after *[a-z_][a-z0-9_]* *[;,] *$"|grep -iwPo "after"|tail -1)" || true
            _col_name="$(f_delete_for_string <<< "${row}"|awk -F ' [Aa][Ff][Tt][Ee][Rr] ' '{print $NF}'|sed 's/ *[;,] *$//g')"
            if [ "$(grep -c "[a-z]" <<< "${_after_first}")x" != "0x" ]
            then #如果使用了after关键字, 则进行特殊处理
                col_name="${_col_name}"
                row="$(sed "s/ ${_after_first} ${_col_name}/ ${_after_first} \`${_col_name}\`/g" <<< "${row}")"
                line="$(sed "s/ ${_after_first} ${_col_name}/ ${_after_first} \`${_col_name}\`/g" <<< "${line}")"
            fi
        done
        echo ${line}
    done > ${alter_file_tmp3}

    if [ "${one_sql_is_error}x" == "0x" ]
    then
        f_logging "ERROR:${fun_name}" "提交的sql文件未通过检测, 请按照上面的提示做出相应的修改您检查" "2" "1"
    elif [ "${all_sql_is_ok}x" == "0x" ] && [ "${check_mode_opt}x" == "strictx" ]
    then
        f_logging "ERROR:${fun_name}" "提交的sql文件未通过检测, 请按照上面的提示做出相应的修改您检查" "2" "1"
    elif [ "${all_sql_is_ok}x" == "0x" ]
    then
        f_logging "WARN:${fun_name}" "提交的sql文件未通过检测, 但是没有使用 '-o strict' 的检查模式, 将继续相应的操作"
    elif [ "${all_sql_is_ok}x" == "1x" ]
    then
        [ "${execute}x" == "0x" ] && f_logging "INFO:${fun_name}" "提交的sql文件通过检测"
    else
        f_logging "WARN:${fun_name}" "遇到未知的错误" "2" "1"
    fi

    table_list=($(awk '{print $3}' ${alter_file_tmp3}))
    table_name_row=1
    one_sql_is_error=1
    declare tmp_table_list
    for table_name in ${table_list[@]}
    do #合并alter操作, 将同一个表的合并成一条alter, 合并后的顺序可能不是用户提交的顺序, 所以要求提交的工单内的sql没有依赖关系
        line="$(sed -n "${table_name_row}p" ${alter_file_tmp3})"
        table_name_row="$((${table_name_row}+1))"
        f_create_test_env "${table_name}" "${tmp_table_list}" >&2 && exe_state="${?}" || exe_state="${?}" #再测试环境create业务表
        [ ${exe_state} -eq 1 ] && one_sql_is_error=0  && continue                     #创建失败就continue
        
        line_tmp="$(f_delete_for_string <<< "${line}")"   #去掉双引号及单引号引起来的字符串

        #判断是不是rename操作
        #去掉rename动作, 如下面三种格式 rename to xxx, ,rename index, ,rename xxx xxx;
        is_rename_table_tmp="$(sed -r 's#\<rename\> [^,]+(|,|;)##gi' <<< "${line_tmp}"|awk '{gsub(/\s+$/, "");print}')"  
        is_rename_table_count="$(grep -wio "rename to" <<< "${line_tmp}"|wc -l)" || true 
        is_rename_count="$(grep -wio "rename" <<< "${line_tmp}"|wc -l)"  || true
        is_rename_tmp="$(sed -r 's#\<rename\> [^,]+(|,|;)##gi' <<< "${line_tmp}"|awk '{gsub(/\s+$/, "");print}'|sed 's/[ ]*$//g')"
        #去掉rename动作以后的字符串等于alter table table_name, 表示有rename操作
        is_rename="$(grep -ic "^alter table ${table_name}$" <<< "${is_rename_tmp}")" || true      
        is_rename_tmp="$(grep -icw "rename" <<< "${line_tmp}")" || true                           #判断是否有rename关键字

        #判断是不是engine操作
        is_engine_tmp="$(grep -icw "engine" <<< "${line_tmp}")" || true                              #判断是否有engine关键字
        #判断是否只有engine=innodb
        is_engine="$(grep -Pic "^alter table ${table_name} engine[ ]*=[ ]*innodb[ ]*;?[ ]*$" <<< "${line_tmp}")" || true 

        if [ "${is_rename_table_count}x" != "0x" ] && [ "${is_rename_count}x" != "1x" ]
        then
            f_logging "ERROR:${fun_name}" "alter sql中的 'rename to' 动作不能和其他动作一起使用 ] [ ${line}" "2" >&2
            one_sql_is_error=0
            continue
        elif [ "${is_rename}x" == "1x" ] || [ "${is_engine}x" == "1x" ] || [ "${is_auto_increment}x" == "1x" ]
        then
            echo "${line}"
            continue
        elif [ "${is_engine_tmp}x" == "1x" ] && [ "${is_engine}x" == "0x" ]
        then
            f_logging "ERROR:${fun_name}" "'engine=innodb' 不能和其他动作一起使用 ] [ ${line}" "2" >&2
            one_sql_is_error=0
            continue
        elif [ "${is_rename_tmp}x" != "0x" ]
        then
            f_logging "ERROR:${fun_name}" "'rename' 不能和其他动作一起使用 ] [ ${line}" "2" >&2
            one_sql_is_error=0
            continue
        else
            [ "$(grep -cw "${table_name}" <<< "${tmp_table_list}")x" != "0x" ] && continue
        fi

        tmp_table_list="${tmp_table_list} ${table_name}"    #将表名保存到临时变量, 已经被合并过的表就不重复判断
        alter_table_first="$(grep -iPv "^alter table [a-zA-Z_]{1,} (rename|engine) " ${alter_file_tmp3}|awk -v t="${table_name}" '{
            if ($3==t) print $0}'|awk '{if(NR==1){for(i=1;i<=3;i++)printf $i " ";printf"\n"}}')" || true  #这是获取alter table操作的前半部分, alter table xxx
        alter_table_end="$(grep -iPv "^alter table [a-zA-Z_]{1,} (rename|engine) " ${alter_file_tmp3}|awk -v t="${table_name}" '{
            if ($3==t) print $0}'|awk '{
                for(i=4;i<=NF;i++)printf $i " ";printf"\n"
            }'|tr "\n" " "|tr ";" ","|sed 's/\(.*\),\(.*\)/\1;\2/'|sed "s/${var_str1}/;/g;s/${var_str2}/,/g")" || true  #这是后半部分, add xxx,add xxx,drop xxx;
        echo "${alter_table_first} ${alter_table_end}"|awk '{for(i=1;i<=NF;i++)printf $i " ";printf"\n"}'
    done > ${alter_file_tmp2}
    if [ "${one_sql_is_error}x" == "0x" ]
    then
        f_logging "ERROR:${fun_name}" "检查sql文件遇到错误, 如上。请重新检查后再次提交 ]" "2" "1"
    elif [ "$(sed '/^$/d' ${alter_file_tmp2}|wc -l)x" == "0x" ]
    then
        f_logging "ERROR:${fun_name}" "${alter_file_tmp2}文件为空" "2" "1"
    fi
    return 0
}

